﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


using MShop.Core.Domain;
using MShop.Core.DataAccess;
using MShop.Core.Configuration;
using MShop.Core.Extensions;
using MShop.Core.Service.Membership;

namespace MShop.Web.Areas.Admin.Controllers
{
    public class CfgController : SecureController
    {
        private readonly IShopSettingsDao _SettingsDao;
        private readonly ICurrenyUnitDao _CurrenyDao;
        private readonly IRoleService _RoleService;
        public CfgController(IShopSettingsDao settingsDao,ICurrenyUnitDao currenyDao,IRoleService roleService)
        {  
            _SettingsDao = settingsDao;
            _CurrenyDao = currenyDao;
            _RoleService = roleService;
        } 
      
        public ActionResult Create()
        {
            var instace = _SettingsDao.GetInstance();
            ViewData["selectlist"] = _CurrenyDao.GetAll().ConvertListItem<CurrenyUnit>("Name", "Id", instace.CurrencyId);
            ViewData["roles"] = _RoleService.FindRoles().ConvertListItem("RoleName", "RoleId", instace.RoleId);
            return View(instace);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(ShopCfgSettings settings)
        {
          
            _SettingsDao.UpdateCfgSettings(settings);   
            return RedirectToAction("create");
        }
    }
}